{extend name="/index/base" /}

{block name="content"}
<div class="layui-card">
    <div class="layui-card-header layuiadmin-card-header-auto">
        <h2>修改角色</h2>
    </div>
    <div class="layui-card-body">
        <form class="layui-form" action="" method="post">
            <div class="layui-form-item">
                <label for="" class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" value="{$data['username']}" lay-verify="required" placeholder="请输入用户名" class="layui-input" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">昵称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" value="{$data['name']}" lay-verify="required" placeholder="请输入昵称" class="layui-input" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                    <input type="email" name="email" value="{$data['email']}" lay-verify="email" placeholder="请输入Email" class="layui-input" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">手机号</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" value="{$data['phone']}" required="phone" placeholder="请输入手机号" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" placeholder="请输入密码" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password_confirmation" placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" class="id" value="{$data['id']}" />
                    <span type="submit" id="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">确 认</span>
                    <a  class="layui-btn" href="{:URL('admin/user/index')}" >返 回</a>
                </div>
            </div>

        </form>
    </div>
</div>

{/block}


{block name="script"}
<script>
    layui.use(['layer','table','form'],function () {
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$ //由于layer弹层依赖jQuery，所以可以直接得到

        //搜索
        $('#submit').click(function () {
            var username = $("input[name='username']").val()
            var name = $("input[name='name']").val()
            var email = $("input[name='email']").val()
            var phone = $("input[name='phone']").val()
            var password = $("input[name='password']").val()
            var password_confirmation = $("input[name='password_confirmation']").val()
            var id = $(".id").val();

            var data = {'username':username,'name':name,'email':email,'phone':phone
                ,'password':password,'password_confirmation':password_confirmation,'id':id};

            $.ajax({
                type: 'POST',
                url: '{:url("admin/user/update")}',
                data: data,
                success: function (ret) {
                    if (ret.code == 200) {
                        layer.msg(ret.msg, {icon: 6, time: 1000}, function () {
                            window.location.href='{:url("admin/user/index")}';
                        });
                    } else {
                        layer.msg(ret.msg);
                    }
                    return false;
                }
            });
        })

    })
</script>
{/block}
